#ifndef Planet_h
#define Planet_h

#include "NamedObject.h"

class Planet : public NamedObject
{
public:
	Planet(std::string p_name, color p_color,
		double p_mass, double p_radius,
		Vector2 p_pos, Vector2 p_velocity)
	: NamedObject(p_name, PLANET, p_color, p_mass, p_radius, p_pos, p_velocity)
	{
		m_health=GC_PLANET_HEALTH;

		m_mana = 0;
		m_global_cooldown_end = 0;
		m_mana_tick_cooldown_end = 0;
	}
	~Planet();

	int getMana() const
	{
		return m_mana;	
	}
	void addMana(unsigned int p_mana)
	{
		unsigned int newmana = m_mana+p_mana;
		if(newmana > GC_PLANET_MANA)
			m_mana = GC_PLANET_MANA;
		else
			m_mana = newmana;
	}
	bool useMana(unsigned int p_mana)
	{
		if (m_mana > p_mana && doSomething())
		{
			m_mana -= p_mana;
			return true;
		}
		return false;
	}
	int getGlobalCooldownEnd() const
	{
		return m_global_cooldown_end;
	}
	bool doSomething()
	{
		if (mtime() >= m_global_cooldown_end)
		{
			m_global_cooldown_end = mtime() + GC_PLANET_GLOBAL_COOLDOWN;
			return true;
		}
		return false;	
	}
	virtual bool useExplosionCharge()
	{
		if (doSomething())
			return NamedObject::useExplosionCharge();
		return false;
	}
	virtual void tick()
	{
		NamedObject::tick();
		if (mtime() > m_mana_tick_cooldown_end)
		{
			addMana(GC_MANA_REGEN_AMOUNT);
			m_mana_tick_cooldown_end = mtime() + GC_MANA_REGEN_TIMESTEP;
		}
	}
protected:
	unsigned int m_mana;

	int m_global_cooldown_end;		
	int m_mana_tick_cooldown_end;	
};

#endif //Planet_h


